<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2023/10/30
 * Time: 20:47
 */

namespace app\reception\controller;


use app\common\model\QuickApp;
use think\Controller;
use think\Db;

class Contract extends Controller
{

    /**
     * 协议
     * @return mixed|\think\response\Json
     */
    public function information()
    {
        $type = input('type');
        $package = input('x-quick-package');
        $apiVersion = input('x-api-version');
        $userToken = input('x-user-token');
        $qa = QuickApp::where('package_name', $package)->findOrFail();
        if (!$qa->subject) {
            return errJson('主体信息不存在');
        }
        $version = 1;
        if (in_array($qa->package_name, ['com.qmkj.ysh', 'com.qmkj.mgyq', 'com.qmkj.yzqy', 'com.qmkj.fywx', 'com.qmkj.yyqz', 'com.qmkj.yzhf', 'com.hmwwl.mjxh'])) {
            $channel_id = Db::table("quick_user")->where("token", $userToken)->value('channel_id');
            if (!$channel_id) {
                $version = 2;
            }
        }
        $this->assign('quick_name', $qa->name);
        $this->assign('company', $qa->subject->subject_name);
        $this->assign('alias', $qa->subject->alias);
        $this->assign('address', $qa->subject->address);
        $this->assign('contact', $qa->subject->contact);
        $this->assign('date', date("Y-m-d", strtotime($qa->create_time)));
        if ($version == 1) {
            if ($type == 'user') {
                return $this->fetch('contract/user');
            } elseif ($type == 'privacy') {
                return $this->fetch('contract/privacy');
            } elseif ($type == 'vip') {
                return $this->fetch('contract/vip');
            } else {
                return errJson('协议类型不存在');
            }
        } else {
            if ($type == 'user') {
                return $this->fetch('contract/tool_user');
            } elseif ($type == 'privacy') {
                return $this->fetch('contract/tool_privacy');
            } else {
                return errJson('协议类型不存在');
            }
        }
    }
}